﻿/*
 * @author: wizardc
 */

using System;
using System.Collections.Generic;
using UnityEngine;

namespace Dou.Resource
{
    /// <summary>
    /// 单个 AB 包状态
    /// </summary>
    public enum AssetBundleState
    {
        /// <summary>
        /// 初始状态
        /// </summary>
        None,
        /// <summary>
        /// 加载中
        /// </summary>
        Loading,
        /// <summary>
        /// 加载完成
        /// </summary>
        Complete,
        /// <summary>
        /// 处于加载中时被调用卸载
        /// </summary>
        Unloaded,
        /// <summary>
        /// 加载完成后被调用卸载，同时启用延迟卸载，但是还没到达卸载时间时
        /// </summary>
        Unloading,
    }
    
    /// <summary>
    /// 单个 AB 信息
    /// </summary>
    public class AssetBundleInfo
    {
        /// <summary>
        /// AB 包名
        /// </summary>
        public string abName;

        /// <summary>
        /// 当前状态
        /// </summary>
        public AssetBundleState state = AssetBundleState.None;

        /// <summary>
        /// 间接依赖项
        /// </summary>
        public string[] dependents;
        
        /// <summary>
        /// 引用次数
        /// </summary>
        public int refCount;

        /// <summary>
        /// AB 包
        /// </summary>
        public AssetBundle assetBundle;

        /// <summary>
        /// 加载完成的回调
        /// </summary>
        public List<Action<AssetBundle>> completeHandler = new List<Action<AssetBundle>>();

        /// <summary>
        /// 卸载剩余时间
        /// </summary>
        public float unloadRemainingTime = 0f;
        
        public AssetBundleInfo(string abName, string[] dependents)
        {
            this.abName = abName;
            this.dependents = dependents;
        }
    }
}
